package com.lms.admin.base.controller;

import com.lms.admin.base.service.ISysMenuService;
import com.lms.admin.base.service.ISysUserService;
import com.lms.admin.base.vo.MenuNode;
import com.lms.common.entity.SysUser;
import com.lms.resource.service.utils.SecurityUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@RequestMapping("/login")
@Tag(name="登录相关请求")
public class LoginController {

    private final ISysMenuService sysMenuService;
    private final ISysUserService sysUserService;

    @Operation(summary = "获取当前登录人信息")
    @GetMapping("/getLoginUser")
    public SysUser getLoginUser() {
        String userName = SecurityUtil.getUserName();
        Map<String, Object> filter = new HashMap<>();
        filter.put("username", userName);
        return (SysUser) sysUserService.getByFilter(filter);
    }

    @Operation(summary = "获取当前登录人所配置的菜单信息")
    @GetMapping("/getLoginMenu")
    public List<MenuNode> getLoginMenu() {
        return sysMenuService.getLoginMenu();
    }

}
